<template>
  <div class="prospecs">
    <mt-header title="手机型号" class="bg-white" fixed>
      <router-link to="/" slot="left">
        <mt-button icon="back"></mt-button>
      </router-link>
    </mt-header>
    <!-- 页面主体 -->
    <div class="main">
      <div class="p-absolute">
        <div class="progress">
          <span>温馨提示：根据实际情况如实描述,最终评估价格更相近</span
          ><span
            ><span>{{ optionId }}</span
            >/10</span
          >
        </div>
      </div>
      <mt-progress :value="optionId * 10"> </mt-progress>
    </div>
    <!-- 手机品牌和标题 -->
    <div class="container">
      <h3 class="title">{{ protitle }}</h3>
      <div class="options">
        <div class="addoption-item" v-for="(option, i) of optionList" :key="i">
          <span><span class="bg-black">*</span>{{ i }}</span>
          <span class="option-title"
            >{{ option }}<span class="update-option">修改</span></span
          >
        </div>
        <div v-for="(option, i) of options" :key="i" v-show="optionId == i + 1">
          <div class="options-title">
            <span class="bg-black">{{ i + 1 }}</span
            ><span class="option-title">{{ option.optiontitle }}</span>
          </div>
          <div class="options-list">
            <button
              v-for="(item, index) of option.optioncontent"
              :key="index"
              @click="selectedOption"
            >
              {{ item }}
            </button>
          </div>
        </div>
      </div>
    </div>
    <!-- 底部询问低价 -->
    <div class="footer">
      <button
        class="lower-price"
        :class="{ disabled: !disabled }"
        :disabled="!disabled"
        @click="addOrder"
      >
        询问低价
      </button>
    </div>
  </div>
</template>
<style lang="scss">
.prospecs {
  padding: 0;
  margin: 0;
  .bg-white {
    border-block: 1px solid #000;
    background: #fff !important;
    color: #000 !important;
  }
  // 页面主体部分
  .main {
    position: relative;
    margin-top: 50px;
    background: #f9faff;
    // 进度条
    .p-absolute {
      position: absolute;
      right: 0;
      left: 0;
      top: -5px;
      z-index: 20;
    }
    .progress {
      display: flex;
      padding: 0 10px;
      justify-content: space-between;
      font-size: 8px;
    }
    // 重写进度条
    .mt-progress {
      height: 0 !important;
      .mt-progress-runway {
        height: 20px !important;
        top: 0 !important;
      }
      .mt-progress-progress {
        border-radius: 2rem;
        height: 20px !important;
        top: 0 !important;
        background: #f00 !important;
      }
    }
  }
  // 评估选项
  .container {
    padding: 10px;
    position: absolute;
    margin: 60px 0 60px;
    background: #f9faff;
    top: 0;
    bottom: 0;
    .title {
      font-size: 16px;
      color: #333;
      font-weight: 800;
    }
    // 选项部分
    .options {
      width: 344px;
      margin: 20px auto 0;
      background: #fff;
      .addoption-item {
        padding-right: 15px;
        display: flex;
        width: 100%;
        height: 46px;
        margin: 10px 0;
        box-shadow: 0px 0px 4px #ccc;
        justify-content: space-between;
        align-items: center;
        .option-title,
        .update-option {
          color: #ccc;
          font-size: 12px;
        }
        .update-option {
          color: #428de4;
          margin-left: 15px;
        }
      }
      .options-title {
        display: flex;
        align-items: center;
      }
      .bg-black {
        display: inline-block;
        width: 18px;
        border-radius: 20px;
        background: #f5f5f5;
        color: #000;
        text-align: center;
        line-height: 40px;
      }
      // 选项
      .options-list {
        button {
          width: 160px;
          height: 65px;
          border: 0;
          margin: 5px 5px;
          border-radius: 12px;
          outline: 0;
          background: #f5f5f5;
          :focus {
            border: 0;
          }
        }
      }
    }
  }
  .footer {
    height: 45px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    button {
      width: 100%;
      height: 100%;
      color: #fff;
      font-weight: 800;
      background: #f74444;
      border: 0;
      :focus {
        outline: 0;
      }
    }
    .disabled {
      background: #bababa;
      color: #fff;
    }
  }
}
</style>
<script>
export default {
  data() {
    return {
      // 跳转过来后商品信息+
      protitle: "",
      proprice: "",
      proid: "",
      propic: "",
      index: 0,
      // 默认禁用免费询问低价，和是否应用禁用的样式
      disabled: false,
      // 当前选中的评估项，和控制上面的进度条
      optionId: 1,
      // 评估选项
      options: [
        {
          id: 1,
          optiontitle: "使用情况",
          optioncontent: [
            "已拆封可正常开机",
            "全新包装未拆封",
            "无法开机/无法进入桌面",
          ],
        },
        {
          id: 2,
          optiontitle: "购买渠道",
          optioncontent: ["港行", "水货", "国行"],
        },
        {
          id: 3,
          optiontitle: "保修剩余时间",
          optioncontent: [
            "过保",
            "一个月以上",
            "保修期剩余3-10个月",
            "保修期剩余超过10个月",
          ],
        },
        {
          id: 4,
          optiontitle: "机身颜色",
          optioncontent: ["黑色", "白色", "金色", "蓝色"],
        },
        {
          id: 5,
          optiontitle: "网络格式",
          optioncontent: ["全网通", "移动版"],
        },
        {
          id: 6,
          optiontitle: "机身内存",
          optioncontent: ["128G", "256G", "512G"],
        },
        {
          id: 7,
          optiontitle: "外观成色",
          optioncontent: [
            "无使用痕迹带全套原装配件",
            "很少使用，完美无使用痕迹",
            "经常使用，完好有轻微划伤",
            "经常使用，外壳有磕碰掉漆",
            "外壳有裂缝/缺失/变形/刻字",
          ],
        },
        {
          id: 8,
          optiontitle: "是否有锁",
          optioncontent: ["无锁", "有锁不可解除"],
        },
        {
          id: 9,
          optiontitle: "维修拆机史",
          optioncontent: [
            "无拆机无修理",
            "拆过机，但没有进行维修",
            "有拆机维修，未涉及到主板",
            "修理过主板",
          ],
        },
        {
          id: 10,
          optiontitle: "屏幕状况",
          optioncontent: [
            "很少使用，显示正常完好",
            "经常使用，显示正常细微色差",
            "换过屏，非原装屏",
            "显示异常/漏液/不显示/断线",
          ],
        },
      ],
      // 保存有哪些选项题
      optionTitleArr: [
        "使用情况",
        "购买渠道",
        "保修剩余时间",
        "机身颜色",
        "网络格式",
        "机身内存",
        "外观成色",
        "是否有锁",
        "维修拆机史",
        "屏幕状况",
      ],
      // 保存用户以选项
      optionList: {},
    };
  },
  methods: {
    selectedOption($event) {
      var optionTitle = this.optionTitleArr[this.optionId - 1];
      this.optionList[optionTitle] = $event.target.innerHTML;
      // 每选择一道题之后就让optionId+1，用于显示下一道题
      this.optionId++;
      // 如果optionId(当前没有选到第10个)执行
      this.optionId == 11 && (this.optionId = 10);
      // 如果optionId选到第10个disabled为true
      this.optionId == 10 && (this.disabled = true);
    },
    // 跳转到订单页
    addOrder() {
      var proprice = Number(this.proprice);
      // 遍历optionList
      if (this.optionList["使用情况"].trim() == "无法开机/无法进入桌面") {
        proprice -= 80;
      }
      if (this.optionList["购买渠道"].trim() == "水货") {
        proprice -= 80;
      }
      if (this.optionList["保修剩余时间"].trim() == "过保") {
        proprice -= 80;
      }
      if (this.optionList["网络格式"].trim() == "移动版") {
        proprice -= 100;
      }
      if (this.optionList["机身内存"].trim() == "128G") {
        proprice -= 80;
      }
      if (this.optionList["外观成色"].trim() == "外壳有裂缝/缺失/变形/刻字") {
        proprice -= 100;
      }
      if (this.optionList["是否有锁"].trim() == "有锁不可解除") {
        proprice -= 80;
      }
      if (this.optionList["维修拆机史"].trim() == "修理过主板") {
        proprice -= 100;
      }
      if (this.optionList["屏幕状况"].trim() == "显示异常/漏液/不显示/断线") {
        proprice -= 300;
      }
      this.proprice = proprice;
      this.$router.push(
        `/order?protitle=${this.protitle}&proprice=${this.proprice}&propic=${this.propic}`
      );
    },
  },
  mounted() {
    this.proid = this.$route.query.proid;
    this.protitle = this.$route.query.protitle;
    this.proprice = this.$route.query.proprice;
    this.propic = this.$route.query.propic;
  },
};
</script>